package com.imau.controller;

import com.alibaba.fastjson.JSON;
import com.imau.service.BrandService;
import com.imau.service.impl.BrandServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "BrandBatchDelServlet", value = "/BrandBatchDelServlet")
public class BrandBatchDelServlet extends HttpServlet {
    //服务
    private BrandService service = new BrandServiceImpl();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        this.doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //获取前端就Id数组
        String idsStr = request.getReader().readLine();




        Integer[] ids = JSON.parseObject(idsStr, Integer[].class);


        //调用服务层


        boolean delete = service.deleteBatchByIds(ids);

        if(delete)
        {
            response.getWriter().write("OK");

        }else {

            response.getWriter().write("ERROR");
        }
    }
}
